package com.imooc.common.thread;

import cn.hutool.core.thread.ThreadUtil;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * Created by deng_wb on 2019/8/17
 */
public class CachedPoolTest {
    public static void main(String[] args) throws Exception{
        ExecutorService service = Executors.newCachedThreadPool(); // 弹性线程池,60s 没有线程操作会回收
        System.out.println(service);

        for (int i = 0; i < 2; i++) {
            service.execute(()->{
                ThreadUtil.sleep(500);
                System.out.println(Thread.currentThread().getName());
            });
        }
        System.out.println(service);
        ThreadUtil.sleep(80, TimeUnit.SECONDS);
        System.out.println(service);
        service.shutdown();
    }

}
